﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using System.Diagnostics;
using UtilityLibrary;
using Microsoft.Xna.Framework;
using MapLibrary.GUI.Components;

namespace GUILibrary
{
    public class TextFormatComponent : Component
    {

        /// <summary>
        /// Text format string
        /// </summary>
        public string TextFormat
        {
            get;
            set;
        }

        /// <summary>
        /// Number of format elements in the TextFormat.
        /// </summary>
        public int NumParams
        {
            get;
            set;
        }

        /// <summary>
        /// Color to display the text.
        /// </summary>
        public Color TextColor
        {
            get;
            set;
        }

        /// <summary>
        /// The items to replace the format elements.
        /// </summary>
        [ContentSerializerIgnore]
        public object[] Params
        {
            get { return ToTrack.GetParams(Name); }
        }

        [ContentSerializerIgnore]
        public IParamTrackable ToTrack
        {
            get;
            set;
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch batch)
        {
            Debug.Assert(ToTrack != null);

            string toDisp = String.Format(TextFormat, Params);

            PrimitiveBrush.RenderText(batch, toDisp, ScreenPosition, TextColor);
        }

        public override void Load(Microsoft.Xna.Framework.Content.ContentManager cm)
        {
            TextColor = new Color(TextColor.R, TextColor.G, TextColor.B, 255);
        }
    }
}
